﻿@using Orchard.Utility.Extensions

@model Orchard.Recipes.ViewModels.RecipesViewModel

@{
    Layout.Title = T("Recipes");
}

@using (Html.BeginFormAntiForgeryPost()) {
    if (Model.Modules.Any()) {
        <ul class="contentItems">
            @foreach (var module in Model.Modules.OrderBy(m => m.Descriptor.Name)) {
                var descriptor = module.Descriptor;
                
                if (string.IsNullOrWhiteSpace(descriptor.Version)) {
                    descriptor.Version = "1.0";
                }

                <li>
                    <div class="summary">
                        <div class="properties">
                            <h2>@descriptor.Name<span> - @T("Version: {0}", descriptor.Version)</span></h2>

                            @foreach (var recipe in module.Recipes) {
                                if (string.IsNullOrWhiteSpace(recipe.Description)) {
                                    recipe.Description = T("No description.").Text;
                                }

                                <br />
                                <div>
                                    <h4>@recipe.Name - @Html.ActionLink(T("Execute").Text, "Recipes", "Admin", new { area = "Orchard.Recipes", moduleId = descriptor.Id, name = recipe.Name }, new { itemprop = "UnsafeUrl" })</h4>
                                    <p style="white-space: pre-line;">@recipe.Description</p>
                                </div>
                            }
                        </div>
                    </div>
                </li>
            }
        </ul>
    }
    else {
        <p>@T("No modules available").Text</p>
    }
}